# import random

# # 定义人生阶段
# phases = ["童年", "少年", "青年", "中年", "晚年"]
#
# # 定义每个阶段的事件，可以自行添加或修改
# phase_events = {
#     "童年": ["出生", "学步", "上幼儿园", "学习游泳", "学习骑自行车"],
#     "少年": ["上小学", "上初中", "获得成绩优异的奖励", "第一次恋爱", "考取大学"],
#     "青年": ["毕业工作", "结婚", "生子", "买房买车", "跳槽换工作"],
#     "中年": ["升职加薪", "投资理财", "身体出现问题", "家庭变故", "考虑退休"],
#     "晚年": ["退休", "养老旅行", "孙子孙女降生", "做志愿者", "去世"]
# }
#
# # 定义随机生成一个新的人生轨迹的函数
# def replay_life():
#     # 让用户输入基本信息
#     print("欢迎使用人生重开模拟器！")
#     name = input("请输入您的姓名：")
#     gender = input("请输入您的性别：")
#     birthplace = input("请输入您的出生地：")
#
#     # 随机生成新的人生轨迹
#     print("正在随机生成您的人生轨迹......")
#     life_events = {}
#     for phase in phases:
#         event = random.choice(phase_events[phase])
#         life_events[phase] = event
#
#     # 输出结果
#     print("{name}，{gender}，{birthplace}人，您本次人生重开的新轨迹如下：".format(name=name, gender=gender, birthplace=birthplace))
#     for phase in phases:
#         print("{phase}阶段：{event}".format(phase=phase, event=life_events[phase]))
#
# # 调用函数进行模拟
# replay_life()

import random
import sys

# 初始化游戏数据
name = ""   # 玩家姓名
gender = "" # 玩家性别
family = 0  # 家庭背景，由出生点决定
looks = 0   # 颜值
physique = 0    # 体质
IQ = 0  # 智力

# 设置初始属性
print("设置初始属性: （可用点数总数为20）")
attribs = ["颜值", "体质", "智力", "家境"]
points = 20
attrib_values = []
for attrib in attribs:
    while True:
        value = int(input(f"输入{attrib}(1-10):"))
        if value < 1 or value > 10 or (points-value < 0 and attrib != "家境"):
            print(f"{attrib}设置有误!重设:")
            continue
        points -= value
        break
    attrib_values.append(value)
looks, physique, IQ, family = attrib_values
print("初始属性设置完毕")
for i, attrib in enumerate(attribs):
    print(f"{attrib}: {attrib_values[i]}")

# 随机生成出生点
print("随机生成出生点：")
point_dict = {
    4: {
        1: "你出生在农村，父母是辛勤劳作的农民",
        2: "你出生在穷乡僻壤，父母是无业游民",
        3: "你出生在镇上，父母感情不和"
    },
    3: {
        1: "你出生在三线城市，父母是公务员",
        2: "你出生在镇上，父母是教师",
        3: "你出生在镇上，父母是个体户"
    },
    2: {
        1: "你出生在大城市，父母是企业高管",
        2: "你出生在大城市，父母是大学教授",
        3: "你出生在大城市，父母是医生"
    },
    1: {
        1: "你出生在帝都，父母是高官政要"
    }
}
point = random.randint(1, 3)
if family == 10:
    point = 1
print(point_dict[family][point])

# 游戏开始
print("游戏开始！")
for age in range(0, 11):
    print(f"你今年{age}岁:")

    # 随机事件和概率
    events = [
        ("你的家庭重男轻女思想严重，你被遗弃了！", 0.01),
        ("你生了一场病: ", 0.2),
        ("同学因为你的长相不愿意跟你玩: ", 0.1),
        ("你有一点笨: ", 0.1)
    ]
    info = f'你今年{age}岁: '
    # 计算随机事件
    event_prob = [event[1] for event in events]
    event_cum_prob = []
    cum_prob = 0
    for prob in event_prob:
        cum_prob += prob
        event_cum_prob.append(cum_prob)
    point = random.random()
    index = len(event_cum_prob) - 1
    for i, cum_prob in enumerate(event_cum_prob):
        if point < cum_prob:
            index = i
            break
    event = events[index][0]
    # 处理随机事件
    if "遗弃" in event:
        print(info + event)
        print("游戏结束")
        sys.exit(0)
    elif "病" in event:
        info += event
        physique -= 1
        if family >= 5:
            info += "父母悉心照顾你，你康复了: "
            physique += 1
        else:
            info += "父母没有精力照顾你，你的状况更差了: "
            physique -= 1
    elif "长相" in event:
        info += event
        physique -= 1
        if IQ > 5:
            info += "你决定用学习填充自己: "
            IQ += 1
        else:
            if gender == "boy":
                info += '你和其他同学经常闹矛盾/打架: '
                physique += 1
                IQ -= 1
            else:
                info += "你的心理状况变差了: "
    elif "笨" in event:
        info += event
        if family >= 8 and age >= 6:
            info += "你的父母给了你多种选择: "
            IQ += 1
            physique += 1
        elif 4 <= family <= 7:
            info += "你的父母给了你更好的教育资源: "
            IQ += 2
            physique -= 1
        else:   # family < 4
            if point % 2 != 0:
                info += "你的父母逼着你学习，你的心理状态很差: "
                IQ += 1
                physique -= 1
            elif gender == 'boy':
                info += "你的父母鼓励你多运动，走体育方向: "
                physique += 1
            else:
                info += "你的父母鼓励你多打扮，走?艺术方向: "
                looks += 1
    else:
        info += "你健康成长: "
        if point < 0.5:
            info += "你的身体越来越好了: "
            physique += 1
        elif point < 0.7:
            info += "你看起来越来越好看了: "
            looks += 1
        elif point < 0.9:
            info += "你的学习越来越好了: "
            IQ += 1
        else:
            info += "父母工作更加顺利了: "
            family += 1
    print(info)

# 游戏结束
print("游戏结束！")
print(f"{name}最终属性：")
for i, attrib in enumerate(attribs):
    print(f"{attrib}: {attrib_values[i]}")
print("成就列表：")
# TODO：实现成就系统及结局评价